# 导包
import logging.handlers
import time

# 创建日志器
logger = logging.getLogger()
# 设置日志打印级别
logger.setLevel("DEBUG")

# 创建处理器
ls = logging.StreamHandler()
lft = logging.handlers.TimedRotatingFileHandler("log666.log", when="M", interval=1, backupCount=2)

# 创建格式化器
fmt = logging.Formatter("%(name)s %(levelno)s %(levelname)s %(pathname)s %(filename)s %(lineno)d %(asctime)s %(message)s %(funcName)s")

# 将格式化器绑定至处理器
lft.setFormatter(fmt)
ls.setFormatter(fmt)

# 将处理器绑定至日志器
logger.addHandler(lft)
logger.addHandler(ls)

# 打印日志
for i in range(10000):
    logging.debug("我是调试级别")
    logging.info("通知")
    logging.warning("警告")
    logging.error("错误")
    logging.critical("致命")
    time.sleep(3)